<template>
	<div>
		<!-- 基础BOM -->
		<v-card>
			<v-card-text>
				<v-row>
					<v-col cols="12" md="7">
						<v-card>
							<v-card-text>
								<v-alert text color="blue-grey">BOM结构树</v-alert>
								<v-container row class="text-subtitle-1 d-flex justify-center  align-left">
									<v-btn class="mt-2" tile color="primary"
										@click="editFatherDialog=true,bomFatherModel={}">
										新增标准BOM
									</v-btn>

									<v-divider class="mx-4" inset vertical></v-divider>
									<v-text-field v-model="bomTreeSearch" append-icon="mdi-magnify"
										label="输入BOM名称或产品类型或特征或设备分类按回车搜索BOM信息,不输入字符默认搜索所有" single-line hide-details
										@keypress.enter="GetBomTree">
									</v-text-field>
								</v-container>
								<v-treeview selectable item-disabled="locked" v-model="selectionBomTrees"
									:items="bomTrees" item-key="id" @input="selectTreeEvent" return-object open-all
									dense>
									<template v-slot:append="{ item, open }">
										<v-tooltip top>
											<template v-slot:activator="{ on, attrs }">
												<v-icon v-bind="attrs" v-on="on" class="ml-2" small tile color="primary"
													@click="openNextNodeDialog(item.model)">
													mdi-plus-thick
												</v-icon>
											</template>
											<span>新增下级节点</span>
										</v-tooltip>
										<v-tooltip top>
											<template v-slot:activator="{ on, attrs }">
												<v-icon v-bind="attrs" v-on="on" class="ml-2" small tile color="success"
													@click="updateBomClick(item.model)">
													mdi-pencil
												</v-icon>
											</template>
											<span>编辑当前节点</span>
										</v-tooltip>
										<v-tooltip top>
											<template v-slot:activator="{ on, attrs }">
												<v-icon v-bind="attrs" v-on="on" class="ml-2" small tile
													:color="item.children.length>0?'green':'red'">
													mdi-check-bold
												</v-icon>
											</template>
											<span>{{item.children.length>0?"已维护下级BOM机构":"未维护下级BOM结构"}}</span>
										</v-tooltip>
										<v-tooltip top>
											<template v-slot:activator="{ on, attrs }">
												<v-icon v-bind="attrs" v-on="on" class="ml-2" small tile color="red"
													@click="deleteBomClick(item.model)">
													mdi-delete
												</v-icon>
											</template>
											<span>删除当前节点及下级节点</span>
										</v-tooltip>
									</template>
								</v-treeview>
								<v-row justify="center">
									<v-col cols="8">
										<v-container class="max-width">
											<!-- total-visible:最大可见分页数 -->
											<!-- prev-icon:是用其它图片做上一页的按钮 -->
											<!-- next-icon:是用其它图片做下一页的按钮 -->
											<!-- circle:分页的按钮都是圆的 -->

											<v-pagination v-model="treePage.pageNumber" class="my-4"
												:length="treePage.totalPages" :total-visible="7"
												prev-icon="mdi-menu-left" next-icon="mdi-menu-right" circle
												@input="changeTreePage">
											</v-pagination>

										</v-container>
									</v-col>
								</v-row>
							</v-card-text>
							<v-alert border="right" justify="center" color="blue-grey" dark>
								BOM总数：{{treePage.totalRecords}}
							</v-alert>
						</v-card>
					</v-col>
					<v-col cols="12" md="5">
						<v-card>
							<!-- 	<v-card-title>
								<v-divider class="mx-4" inset vertical></v-divider>
								<v-row class="mt-2">
									<v-col cols="2" sm="3" md="2">
										<v-text-field label="bom编码" v-model="bomQuery.code" dense outlined>
										</v-text-field>
									</v-col>
									<v-col cols="2" sm="3" md="2">
										<v-text-field label="bom名称" v-model="bomQuery.name" dense outlined>
										</v-text-field>
									</v-col>


									<v-col cols="12" sm="3" md="2">
										<v-select label="状态" v-model="bomQuery.bomstatus" :items="bomStatusItems" dense
											outlined>
										</v-select>
									</v-col>
									<v-col cols="12" sm="3" md="2">
										<v-select label="类型" v-model="bomQuery.bomtype" :items="bomTypeItems" dense
											outlined>
										</v-select>
									</v-col>

									<v-col cols="12" sm="2" md="2">
										<v-row>
											<v-col cols="12" md="6">
												<v-btn depressed color="primary" @click="loadPages">查询
												</v-btn>
											</v-col>
											<v-col cols="12" md="6">
												<v-btn class="ml-3" depressed color="primary" @click="refreshLoadPages">
													刷新</v-btn>
											</v-col>
										</v-row>
									</v-col>
								</v-row>
							</v-card-title>
 -->
							<v-card-text>
								<v-alert text color="blue-grey">BOM详细信息</v-alert>
								<v-data-table :headers="bomHeaderList" :items="bomDataList" small fixed-header
									item-key="id" dense show-select class="text-no-wrap" loading-text="正在加载请稍等......"
									:loading="bomLoading" :options.sync="bomOptions" :footer-props="vuetifyDefaultPage"
									:server-items-length="bomTotalCount">
									<template v-slot:item.picurl="{ item }">
										<a @click="openLookPicsClick(item.picurl)">查看文件</a></td>
									</template>
									<template v-slot:item.actions="{ item }">
										<div>
											<!-- 	<v-btn class="ml-2" small tile color="primary"
												@click="openNextNodeDialog(item)">
												新增下级节点
											</v-btn> -->
											<v-btn class="ml-2" small tile color="primary"
												@click="updateBomClick(item)">
												修改
											</v-btn>
											<v-btn class="ml-2" small tile color="red" @click="deleteBomClick(item)">
												删除
											</v-btn>
										</div>
									</template>

								</v-data-table>
							</v-card-text>
						</v-card>
					</v-col>
				</v-row>

			</v-card-text>
		</v-card>
		<v-dialog v-model="editFatherDialog" width="600">
			<v-card>
				<v-card-title>维护BOM信息</v-card-title>
				<v-card-text>
					<v-col cols="12">
						<v-text-field label="BOM编号(自动生成)" disabled v-model="bomFatherModel.code" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-text-field label="BOM名称(必填)" v-model="bomFatherModel.name" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-text-field label="产品型号(必填)" :disabled="bomFatherModel.id>0" v-model="bomFatherModel.model"
							dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-text-field label="设备分类(必填)" :disabled="bomFatherModel.id>0"
							v-model="bomFatherModel.equicategory" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-text-field label="产品类型(必填)" :disabled="bomFatherModel.id>0"
							v-model="bomFatherModel.productiontype" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-text-field label="特征(必填)" :disabled="bomFatherModel.id>0"
							v-model="bomFatherModel.characteristic" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-text-field label="版本号" 
							v-model="bomFatherModel.version" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12">
						<v-btn width="100%" tile color="primary" @click="openLookPicsClick(bomFatherModel.picurl)">
							文件数量：{{bomFatherModel.picurl==null?0:JSON.parse(bomFatherModel.picurl).length}},点击查询
						</v-btn>
					</v-col>

					<v-col cols="12" v-if="bomFatherModel.id>0">
						<v-row>
							<v-col cols="12">
								<v-btn width="100%" tile color="primary"
									:disabled="bomFatherModel.name==null||bomFatherModel.model==null"
									@click="showUpLoadCommentClick">上传文件</v-btn>
							</v-col>
							<v-col cols="12">
								<uploadfile v-if="isSshowUpLoadFatherBomPic" :UpLoad="UpLoadFatherBomPic"
									:callBackPath="UpLoadFatherBomPicCallBackPath">
								</uploadfile>
							</v-col>
						</v-row>
					</v-col>

				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="success" class="mr-4" text @click="bomFatherSubmit">确认</v-btn>
					<v-btn color="warning" class="mr-4" text @click="bomFatherClose">取消</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>

		<v-dialog v-model="editBomChildrenDialog" width="1200">
			<v-card>
				<v-card-title>维护BOM结构树</v-card-title>
				<v-card-text>
					<v-row>
						<v-col cols="12" md="4">
							<v-text-field label="BOM编号(自动生成)" disabled v-model="bomChildrenModel.code" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="4" v-if="bomChildrenModel.parent!=null">

							<v-text-field v-if="bomChildrenModel.id>0" label="上级节点(必填)"
								v-model="bomChildrenModel.tempparentname" disabled dense outlined>
							</v-text-field>
							<v-text-field v-else label="上级节点(必填)" v-model="bomChildrenModel.parent.name" disabled dense
								outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="4" v-if="bomChildrenModel.parent!=null">
							<v-text-field v-if="bomChildrenModel.id>0" label="上级节点类型(必填)"
								v-model="bomChildrenModel.tempbomtypename" disabled dense outlined>
							</v-text-field>
							<v-text-field v-else label="上级节点类型(必填)" v-model="bomChildrenModel.parent.bomtypename"
								disabled dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="4">
							<v-text-field label="BOM名称(必填)" v-model="bomChildrenModel.name" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="4">
							<v-select label="BOM类型(必填)" :disabled="bomChildrenModel.id>0"
								v-model="bomChildrenModel.bomtype" :items="modelUseBomTypeItems"
								@input="bomTypeSelectEvent" dense outlined>
							</v-select>
						</v-col>
						<v-col cols="12" md="4">
							<v-select label="BOM子类型(必填)" :disabled="bomChildrenModel.id>0"
								v-model="bomChildrenModel.bomchildrentype" :items="workOrderTypeItems"
								@input="bomChildrenTypeSelectEvent" dense outlined>
							</v-select>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="默认用料名称" :style="inventoryModel.cinvcode"
								v-model="bomChildrenModel.default_material_name" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="默认用料型号" v-model="bomChildrenModel.default_material_specifications"
								dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="默认用料数量" :rules="NeedQtyRule"
								v-model="bomChildrenModel.default_material_qty" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="默认用料单套数量" :rules="NeedQtyRule"
								v-model="bomChildrenModel.default_material_single_qty" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="默认用料单位" v-model="bomChildrenModel.default_material_unit" dense
								outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-btn tile color="primary" @click="defaultMaterialClick">选择默认用料</v-btn>
						</v-col>


						<!-- <v-col cols="12" md="2">
							<v-text-field label="可替代用料名称" :style="inventoryModel.cinvcode"
								v-model="bomChildrenModel.replace_material_name" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="可替代用料型号" v-model="bomChildrenModel.replace_material_specifications"
								dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="可替代用料数量" :rules="NeedQtyRule"
								v-model="bomChildrenModel.replace_material_qty" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="替代用料单套数量" :rules="NeedQtyRule"
								v-model="bomChildrenModel.replace_material_single_qty" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-text-field label="可替代用料单位" v-model="bomChildrenModel.replace_material_unit" dense
								outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12" md="2">
							<v-btn tile color="primary" @click="replaceMaterialClick">选择可替代用料</v-btn>
						</v-col> -->
						<v-col cols="12">
							<uploadfile :UpLoad="UpLoadChildrenBomPic" :callBackPath="UpLoadChildrenBomPicCallBackPath">
							</uploadfile>
						</v-col>
						<v-col cols="12">
							<v-text-field label="表面处理" v-model="bomChildrenModel.surface_treatment" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12">
							<v-text-field label="备注" v-model="bomChildrenModel.description" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12">
							<v-text-field label="版本号" 
								v-model="bomChildrenModel.version" dense outlined>
							</v-text-field>
						</v-col>
						<v-col cols="12">
							<v-checkbox label="是否外协" v-model="bomChildrenModel.iswout" dense outlined>
							</v-checkbox>
						</v-col>
					</v-row>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="success" class="mr-4" text @click="bomhildrenSubmit">确认</v-btn>
					<v-btn color="warning" class="mr-4" text @click="bomhildrenClose">取消</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<inventorycomment :materialComment="materialDefaultComment" :setMaterialcallBack="setDefaultMaterialcallBack">
		</inventorycomment>
		<inventorycomment :materialComment="materialReplaceComment" :setMaterialcallBack="setReplaceMaterialcallBack">
		</inventorycomment>
		<showfiledialog :filesModel="fileDialogComment"></showfiledialog>
	</div>

</template>

<script>
	import {
		mapActions
	} from 'vuex'
	import showfiledialog from '../../comments/ShowFilesDialog.vue'
	import inventorycomment from '../components/InventoryDataList.vue'
	import uploadfile from '../../mes/components/UploadFile.vue'
	export default {
		name: 'document_bom_basic',
		components: {
			uploadfile,
			inventorycomment,
			showfiledialog
		},
		data: () => ({
			bomQuery: {
				name: '',
				code: '',
				bomtype: 1,
				bomstatus: 1,
			},
			NeedQtyRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字',
				v => v > 0 || '需求量不能小于0'
			],
			enums: ['BomStatus', 'BomType', 'WorkOrderType'],
			bomStatusItems: [],
			bomTypeItems: [],
			workOrderTypeItems: [],
			modelUseBomTypeItems: [],
			modelUseWorkOrderTypeItems: [],
			bomHeaderList: [],
			bomDataList: [],
			bomTotalCount: 0,
			bomLoading: true,
			bomOptions: { //页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [5, 10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			bomTreeSearch: '',
			selectionBomTrees: [],
			bomTrees: [],
			//主BOM
			editFatherDialog: false,
			bomFatherModel: {},
			isSshowUpLoadFatherBomPic: false,
			UpLoadFatherBomPic: {
				isUploadSingleImage: false,
				isUploadMultipleFiles: true,
				fileUrl: `PDM/PDMBomBasic/ImportBasic?`,
				type: 50
			},
			UpLoadChildrenBomPic: {
				isUploadSingleImage: false,
				isUploadMultipleFiles: true,
				type: 60
			},
			//子BOM
			editBomChildrenDialog: false,
			bomChildrenModel: {},
			//主物料弹出框
			materialDefaultComment: {
				dialog: false,
				bself: true, // 是否自制
				bpurchase: null, // 是否采购
				bproducing: null, // 是否在制
				loadInventoryPageUrl: ``,
				loadInventoryClassUrl: ``,
				loadUnitsUrl: ``,
				queryInvClassTreeUrl: `PDM/PDMBomBasic/GetInvclassTree?iinvcgrade=`
			},
			//替代料弹出框
			materialReplaceComment: {
				dialog: false,
				bself: true, // 是否自制
				bpurchase: null, // 是否采购
				bproducing: null, // 是否在制
				loadInventoryPageUrl: ``,
				loadInventoryClassUrl: ``,
				loadUnitsUrl: ``,
				queryInvClassTreeUrl: `PDM/PDMBomBasic/GetInvclassTree?iinvcgrade=`
			},
			fileDialogComment: {
				dialog: false,
				files: []
			},
			inventoryModel: {},
			treePage: {
				totalPages: 0,
				pageNumber: 1,
				pageSize: 10,
				totalRecords: 0
			},
		}),
		watch: {
			bomOptions: {
				handler() {
					this.loadPages()
				},
				deep: true
			},
		},
		created() {
			this.getHeaderList()
			this.loadEnums()
			this.changeTreePage(1)
		},
		methods: {
			...mapActions('mes/common', [
				//获取物料信息
				'LoadType'
			]),  
			//查看图片
			openLookPicsClick(pathstrs) {
				if (pathstrs != null && pathstrs != undefined && pathstrs != '') {
					this.fileDialogComment.dialog = true
					this.fileDialogComment.files = JSON.parse(pathstrs)
				}
			},
			async loadEnums() {
				var items = await this.LoadType({
					pramterEnums: this.enums
				})
				this.bomStatusItems = items.filter(r => r.enumName == this.enums[0])
				this.bomTypeItems = items.filter(r => r.enumName == this.enums[1])
				this.modelUseBomTypeItems = items.filter(r => r.enumName == this.enums[1] && r.value != 1)
				this.workOrderTypeItems = items.filter(r => r.enumName == this.enums[2])
				this.modelUseWorkOrderTypeItems = items.filter(r => r.enumName == this.enums[2])

			},
			async changeTreePage(pageNumber) {
				this.treePage.pageNumber = pageNumber
				await this.GetBomTree()
			},
			async GetBomTree() {
				var response = await this.$httpRequest({
					url: `PDM/PDMBomBasic/GetBomTree?isOpenLock=false&codeOrName=${this.bomTreeSearch}&pageNumber=${this.treePage.pageNumber}&pageSize=${this.treePage.pageSize}`,
					method: 'post'
				})

				if (response.status == 1) {
					this.bomTrees = response.data.trees
					this.treePage.totalPages = response.data.pagination.totalPages
					this.treePage.totalRecords = response.data.pagination.totalRecords
				} else {
					this.$message.error(response.info)
				}
			},
			async loadPages(keypaths = []) {
				this.bomLoading = true
				var response = await this.$httpRequest({
					url: `PDM/PDMBomBasic/LoadPage?code=${this.bomQuery.code}&name=${this.bomQuery.name}&bomstatus=${this.bomQuery.bomstatus}&bomtype=${this.bomQuery.bomtype}&pageNumber=${this.bomOptions.page}&pageSize=${this.bomOptions.itemsPerPage}`,
					method: 'post',
					data: keypaths
				})
				if (response.status == 1) {
					this.bomDataList = response.data.result
					this.bomTotalCount = response.data.pagination.totalRecords
					this.bomLoading = false
				} else {
					this.$message.error(response.info)
				}
			},
			async refreshLoadPages() {
				this.bomQuery.name = ''
				this.bomQuery.code = ''
				this.bomQuery.bomtype = null
				this.bomQuery.bomstatus = null

			},
			selectTreeEvent(tree) {

				if (tree != null && tree.length > 0) {
					var keypaths = tree.map(r => r.keypath)
					this.refreshLoadPages()
					this.loadPages(keypaths)
				}
			},
			//编辑 bom设备、部件对话框
			updateBomClick(item) {
				//设备
				// productModel
				// bomName=${this.bomFatherModel.name}&productModel=${this.bomFatherModel.model}&equicategory=${this.bomFatherModel.equicategory}&productiontype=${this.bomFatherModel.productiontype}&characteristic=${this.bomFatherModel.characteristic}
				if (item.bomtype == 1) {
					this.editFatherDialog = true
					this.bomFatherModel = item
					this.bomFatherModel.bomName = item.name
					this.bomFatherModel.model = item.model
					this.bomFatherModel.equicategory = item.equicategory
					this.bomFatherModel.productiontype = item.productiontype
					this.bomFatherModel.characteristic = item.characteristic
				} else {
					this.bomTypeSelectEvent(this.bomChildrenModel.bomtype)
					this.editBomChildrenDialog = true
					this.bomChildrenModel = item
					this.bomChildrenModel.tempbomtypename = this.bomChildrenModel.bomtypename
					this.bomChildrenModel.tempparentname = this.bomChildrenModel.parentname

				}
			},
			//删除BOM
			async deleteBomClick(item) {
				var response = await this.$httpRequest({
					url: `PDM/PDMBomBasic/DeleteBom?keypath=${item.keypath}`,
					method: 'delete'
				})
				if (response.status == 1) {
					this.$message.success(response.info)
					// await this.loadPages()
					await this.GetBomTree()
				} else {
					this.$message.error(response.info)
				}
			},

			async bomFatherSubmit() {
				var url;
				if (this.bomFatherModel.id > 0) {
					url = `PDM/PDMBomBasic/UpdateBom`
				} else {
					url = `PDM/PDMBomBasic/AddBom`
				}
				this.bomFatherModel.bomtype = 1
				var response = await this.$httpRequest({
					url: url,
					method: 'post',
					data: this.bomFatherModel
				})
				if (response.status == 1) {
					this.$message.success(response.info)
					this.bomFatherClose()
					await this.loadPages()
					await this.GetBomTree()
				} else {
					this.$message.error(response.info)
				}
			},
			bomFatherClose() {
				this.bomFatherModel = {}
				this.editFatherDialog = false
			},
			UpLoadFatherBomPicCallBackPath(callbackModel) {
				this.bomFatherModel.jjjson = callbackModel.jjjson
				this.bomFatherModel.wgjson = callbackModel.wgjson
				this.bomFatherModel.picurl = JSON.stringify(callbackModel.file)
			},
			async bomhildrenSubmit() {
				var url;

				if (this.bomChildrenModel.id > 0) {
					url = `PDM/PDMBomBasic/UpdateBom`
				} else {
					url = `PDM/PDMBomBasic/AddBom`
				}

				var response = await this.$httpRequest({
					url: url,
					method: 'post',
					data: this.bomChildrenModel
				})
				if (response.status == 1) {
					this.$message.success(response.info)
					this.bomhildrenClose()
					await this.GetBomTree()
				} else {
					this.$message.error(response.info)
				}
			},
			bomTypeSelectEvent(type) {
				if (type == 5) //外购件
				{
					this.materialDefaultComment.bself = true
					this.materialReplaceComment.bself = true
					this.materialDefaultComment.bpurchase = true
					this.materialReplaceComment.bpurchase = true
				} else {
					this.materialDefaultComment.bself = true
					this.materialReplaceComment.bself = true
				}
			},
			bomhildrenClose() {
				this.bomChildrenModel = {}
				this.editBomChildrenDialog = false
			},
			UpLoadChildrenBomPicCallBackPath(fileUrlItemJson) {
				this.bomChildrenModel.picurl = JSON.stringify(fileUrlItemJson)
			},
			defaultMaterialClick() {
				this.bomChildrenModel.default_material_code = ''
				this.bomChildrenModel.default_material_name = ''
				this.bomChildrenModel.default_material_qty = ''
				this.bomChildrenModel.default_material_unit = ''
				this.materialDefaultComment.dialog = true
				this.materialDefaultComment.loadInventoryPageUrl = `PDM/PDMBomBasic/LoadInventoryPage`
				this.materialDefaultComment.loadInventoryClassUrl = `PDM/PDMBomBasic/loadInventoryClass`
				this.materialDefaultComment.loadUnitsUrl = `PDM/PDMBomBasic/loadUnits`
			},
			replaceMaterialClick() {
				this.bomChildrenModel.replace_material_code = ''
				this.bomChildrenModel.replace_material_name = ''
				this.bomChildrenModel.replace_material_qty = ''
				this.bomChildrenModel.replace_material_unit = ''
				this.materialReplaceComment.dialog = true
				this.materialReplaceComment.loadInventoryPageUrl = `PDM/PDMBomBasic/LoadInventoryPage`
				this.materialReplaceComment.loadInventoryClassUrl = `PDM/PDMBomBasic/loadInventoryClass`
				this.materialReplaceComment.loadUnitsUrl = `PDM/PDMBomBasic/loadUnits`
			},
			setDefaultMaterialcallBack(inventory) {
				this.inventoryModel = inventory
				this.bomChildrenModel.default_material_code = inventory.cinvcode
				this.bomChildrenModel.default_material_name = inventory.cinvname
				this.bomChildrenModel.default_material_specifications = inventory.cinvstd
				this.bomChildrenModel.default_material_unit = inventory.unitname
				console.log(this.bomChildrenModel.default_material_unit)
			},
			setReplaceMaterialcallBack(inventory) {
				this.inventoryModel = inventory
				this.bomChildrenModel.replace_material_code = inventory.cinvcode
				this.bomChildrenModel.replace_material_name = inventory.cinvname
				this.bomChildrenModel.replace_material_specifications = inventory.cinvstd
				this.bomChildrenModel.replace_material_unit = inventory.unitname
			},
			openNextNodeDialog(bom) {
				this.modelUseBomTypeItems = this.bomTypeItems.filter(r => r.value != 1)
				this.workOrderTypeItems = this.modelUseWorkOrderTypeItems
				this.editBomChildrenDialog = true
				this.bomChildrenModel = {}
				this.bomChildrenModel.parent = bom
				//上级节点不是设备
				if (this.bomChildrenModel.parent.bomtype != 1) {
					// 下级节点只能等于上级节点的类型  ： 电控、加工、装配 .....
					this.bomChildrenModel.bomchildrentype = this.bomChildrenModel.parent.bomchildrentype
					// this.workOrderTypeItems = this.modelUseWorkOrderTypeItems.filter(r => r.value == this.bomChildrenModel
					// 	.bomchildrentype)
				}
			},
			bomChildrenTypeSelectEvent(type) {
				// BOM子类型选择了：装配、电控 同时 上级节点是设备
				if ((type == 1 || type == 2) && this.bomChildrenModel.parent.bomtype == 1) {
					// BOM类型只能是部件，MES根据部件生成 装配、电控工单
					this.bomChildrenModel.bomtype = 2
					this.modelUseBomTypeItems = this.bomTypeItems.filter(r => r.value == 2)
				} else {
					this.modelUseBomTypeItems = this.bomTypeItems.filter(r => r.value != 1)
				}
			},
			showUpLoadCommentClick() {
				this.isSshowUpLoadFatherBomPic = true
				this.UpLoadFatherBomPic.fileUrl =
					`PDM/PDMBomBasic/ImportBasic?bomName=${this.bomFatherModel.name}&productModel=${this.bomFatherModel.model}&equicategory=${this.bomFatherModel.equicategory}&productiontype=${this.bomFatherModel.productiontype}&characteristic=${this.bomFatherModel.characteristic}&`

			},
			getHeaderList() {
				this.bomHeaderList = [{
						text: '操作',
						align: 'center',
						value: 'actions',
						filterable: false,
						class: 'fixed'
					},
					{
						text: 'BOM编号',
						align: 'left',
						value: 'code',
						filterable: false,
						class: 'fixed'
					},
					{
						text: 'BOM名称',
						align: 'left',
						value: 'name',
						filterable: false,
						class: 'fixed'
					},
					{
						text: 'BOM类型',
						align: 'left',
						value: 'bomtypename',
						filterable: false,
						class: 'fixed'
					},
					{
						text: 'BOM子类型',
						align: 'left',
						value: 'bomchildrentypename',
						filterable: false,
						class: 'fixed'
					},
					{
						text: 'BOM状态',
						align: 'left',
						value: 'bomstatusname',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '产品型号',
						align: 'left',
						value: 'model',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '结构',
						align: 'left',
						value: 'keypathname',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '设备分类',
						align: 'center',
						value: 'equicategory',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '产品类型',
						align: 'center',
						value: 'productiontype',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '特征',
						align: 'center',
						value: 'characteristic',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '默认用料规格',
						align: 'center',
						value: 'default_material_specifications',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '默认用料数量',
						align: 'center',
						value: 'default_material_qty',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '默认用料单位',
						align: 'center',
						value: 'default_material_unit',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '查看图纸',
						align: 'left',
						value: 'picurl',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '等级',
						align: 'center',
						value: 'level',
						filterable: false,
						class: 'fixed'
					},
					{
						text: 'BOM维护人姓名',
						align: 'center',
						value: 'createuser',
						filterable: false,
						class: 'fixed'
					},
				]
			},
		}
	}
</script>
